$(function() {
    /*
    * 添加商品(单品)
    * */
    $('.show').on('click','.adds',function () {
        var id = $(this).find('.goods_id').val();
        var format = $(this).find('.format').val();
        var setmeal = $(this).find('.stemeal').val();
        var orderid = $('#orderid').val();
        $.post("cart", {id: id, format: format, orderid: orderid,setmeal: setmeal}, function (date) {
            var data = date.msg.data;
            var pay = date.msg.pay;
            $('.all').html(pay.all_money);
            $('.orderid').html(pay.orderid + '<input type="hidden" id="orderid" value="' + pay.orderid + '">');
            var src = '';
            $.each(data, function (k, val) {
                var k=k+1;
                src += '<ul id="cd" class="am-list am-margin-bottom-xs am-avg-sm-4 am-avg-md-4 am-avg-lg-4 am-text-lg am-text-center am-padding-sm color02">' +
                    '<li>' +
                     k+
                    '</li>'+
                    '<li>'+
                    val.g_goodsname + '(' + val.formatname + ')' +
                    '</li>'+
                    '<li>1</li>'+
                    '<li class="press">&yen'+
                    val.price +
                    '<em class="am-icon-chevron-down am-padding-left"></em></li></ul>'+
                    '<div class="am-g am-padding-sm yc cs">' +
                    '<div class="am-u-sm-6 am-u-md-6 am-u-lg-6 am-padding-right-0">' +
                    '<a href="#" class="am-btn am-btn-danger del am-radius">' +
                    '<input type="hidden" class="dels" value="'+val.id+'">'+
                    '<i class="am-icon-trash am-padding-right-xs">' +
                    '</i>删除' +
                    '</a>' +
                    '</div>' +
                    /*'<div class="am-u-sm-6 am-u-md-6 am-u-lg-6 am-padding-left-0">' +
                    '<div class="am-input-group">' +
                    '<span class="am-input-group-label am-icon-plus">' +
                    '</span><input type="text" class="am-form-field">' +
                    '<span class="am-input-group-label am-icon-minus">' +
                    '</span>' +
                    '</div>' +
                    '</div>' +*/
                    '</div>';
                $('#cart').html(src);
            })
        }, 'json')
    });
    /*
    * 清空
    * */
    $('#clear').click(function()
    {
        var orderid = $('#orderid').val();
        $.post('emptys',{orderid:orderid},function (date) {
            var src="";
            $('.all').html(src);
            $('.orderid').html(  '<input type="hidden" id="orderid" value="">');
            $('#cart').html(src);
        },'json');
    })
    /*
    * 关闭打开按钮
    * */
    $('#cart').on('click','.am-padding-left',function(){
        $(this).parent().parent().next().toggleClass('yc');
    })
    /*
    * 删除
    * */
    $('#cart').on('click', '.del', function () {
        var k = $(this).children('input').val();
        var orderid = $('#orderid').val();
        $.post("del", {k: k,orderid:orderid}, function (date) {
                var data = date.msg.data;
                if(data != ''){
                    var pay = date.msg.pay;
                    $('.all').html(pay.all_money);
                    $('.orderid').html(pay.orderid + '<input type="hidden" id="orderid" value="' + pay.orderid + '">');
                    var src = '';
                    $.each(data, function (k, val) {
                        var k=k+1;
                        src += '<ul id="cd" class="am-list am-margin-bottom-xs am-avg-sm-4 am-avg-md-4 am-avg-lg-4 am-text-lg am-text-center am-padding-sm color02">' +
                            '<li>' +
                            k+
                            '</li>'+
                            '<li>'+
                            val.g_goodsname + '(' + val.formatname + ')' +
                            '</li>'+
                            '<li>1</li>'+
                            '<li class="press">&yen'+
                            val.price +
                            '<em class="am-icon-chevron-down am-padding-left"></em></li></ul>'+
                            '<div class="am-g am-padding-sm yc cs">' +
                            '<div class="am-u-sm-6 am-u-md-6 am-u-lg-6 am-padding-right-0">' +
                            '<a href="#" class="am-btn am-btn-danger del am-radius">' +
                            '<input type="hidden" class="dels" value="'+val.id+'">'+
                            '<i class="am-icon-trash am-padding-right-xs">' +
                            '</i>删除' +
                            '</a>' +
                            '</div>' +
                            /*'<div class="am-u-sm-6 am-u-md-6 am-u-lg-6 am-padding-left-0">' +
                            '<div class="am-input-group">' +
                            '<span class="am-input-group-label am-icon-plus">' +
                            '</span><input type="text" class="am-form-field">' +
                            '<span class="am-input-group-label am-icon-minus">' +
                            '</span>' +
                            '</div>' +
                            '</div>' +*/
                            '</div>';
                        $('#cart').html(src);
                    })
                }else{
                    var pay = date.msg.pay;
                    $('.all').html(pay.all_money);
                    $('.orderid').html(  '<input type="hidden" id="orderid" value="">');
                    var src = '';
                    $('#cart').html(src);
                }

        }, 'json')
    })
    $('#puorder').click(function () {
        var orderid = $('#orderid').val();
        layer.open({
            type: 2,
            title: '商品挂单',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['893px', '600px'],
            content: 'updata?orderid='+orderid,//视图路径
            yes:function(index,layero){
                var orderid=window[layero.find('iframe')[0]['name']];
                var flag = iframeWin.mySubmit();
                 alert(flag);
            }
        })
    });
})